package cn.stylefeng.guns.modular.tool.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.tool.entity.ToolExpressExcel;
import cn.stylefeng.guns.modular.tool.mapper.ToolExpressExcelMapper;
import cn.stylefeng.guns.modular.tool.model.params.ToolExpressExcelParam;
import cn.stylefeng.guns.modular.tool.model.result.ToolExpressExcelResult;
import  cn.stylefeng.guns.modular.tool.service.ToolExpressExcelService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * 快递统计导入 服务实现类
 */
@Service
public class ToolExpressExcelServiceImpl extends ServiceImpl<ToolExpressExcelMapper, ToolExpressExcel> implements ToolExpressExcelService {

    @Override
    public void add(ToolExpressExcelParam param){
        ToolExpressExcel entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(ToolExpressExcelParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(ToolExpressExcelParam param){
        ToolExpressExcel oldEntity = getOldEntity(param);
        ToolExpressExcel newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public ToolExpressExcelResult findBySpec(ToolExpressExcelParam param){
        return null;
    }

    @Override
    public List<ToolExpressExcelResult> findListBySpec(ToolExpressExcelParam param){
        return this.baseMapper.findListBySpec(param);
    }

    @Override
    public LayuiPageInfo findPageBySpec(ToolExpressExcelParam param,String condition){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param,condition);
        return LayuiPageFactory.createPageInfo(page);
    }

    private Serializable getKey(ToolExpressExcelParam param){
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private ToolExpressExcel getOldEntity(ToolExpressExcelParam param) {
        return this.getById(getKey(param));
    }

    private ToolExpressExcel getEntity(ToolExpressExcelParam param) {
        ToolExpressExcel entity = new ToolExpressExcel();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

	@Override
	public boolean saveBatchList(List<ToolExpressExcelParam> list) {
		return this.baseMapper.saveBatchList(list);
	}

	@Override
	public void deleteBySpec(ToolExpressExcelParam toolExpressExcelParam) {
		 this.baseMapper.deleteBySpec(toolExpressExcelParam);
	}

	@Override
	public List<ToolExpressExcelResult> findSumListBySpec(ToolExpressExcelParam param) {
		return this.baseMapper.findSumListBySpec(param);
	}

	@Override
	public List<ToolExpressExcelResult> findSumListBySpec2(ToolExpressExcelParam param) {
		return this.baseMapper.findSumListBySpec2(param);
	}

	@Override
	public List<ToolExpressExcelResult> findListBySpecOne(ToolExpressExcelParam param,Long operateId) {
		return this.baseMapper.findListBySpecOne(param, operateId);
	}

	@Override
	public void updateBySpec(ToolExpressExcelParam param) {
		this.baseMapper.updateBySpec(param);
	}

	@Override
	public void updateBySpec2(ToolExpressExcelParam param) {
		this.baseMapper.updateBySpec2(param);
	}

	@Override
	public LayuiPageInfo findPageTjnumssBySpec(ToolExpressExcelParam param, String condition,Long operateId) {
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.findPageTjnumssBySpec(pageContext, param,condition, operateId);
        return LayuiPageFactory.createPageInfo(page);
	}

	@Override
	public LayuiPageInfo findPageTjnumssSumBySpec(ToolExpressExcelParam param, String condition,
			Long operateId) {
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.findPageTjnumssSumBySpec(pageContext, param,condition, operateId);
        return LayuiPageFactory.createPageInfo(page);
	}

}
